package ghr.day0109.travelt.dao.impl;

import ghr.day0109.travelt.dao.ScenicDao;
import ghr.day0109.travelt.entity.ScenicSpot;
import ghr.day0109.travelt.utils.BaseDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ScenicDaoImpl extends BaseDao implements ScenicDao {
    @Override
    public List<ScenicSpot> queryAllScenic() {
        List<ScenicSpot> spotList = new ArrayList<>();
        ScenicSpot scenicSpot = null;
        String sql =  "select ss_id, ss_name, ss_duration, ss_content  from scenic_spot";
        super.executeQuery(sql);
        try{while(rs.next()){
            scenicSpot = new ScenicSpot();
            scenicSpot.setSsId(rs.getString("ss_id"));
            scenicSpot.setSsName(rs.getString("ss_name"));
            scenicSpot.setSsDuration(rs.getString("ss_duration"));
            scenicSpot.setSsContent(rs.getString("ss_content"));
            spotList.add(scenicSpot);
        }
        }catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs,pstmt,conn);
        }
        return spotList;
    }

    @Override
    public List<ScenicSpot> queryOneScenic(String id) {
        List<ScenicSpot> spotList = new ArrayList<>();
        ScenicSpot scenicSpot = null;
        String sql = "select ss_id, ss_name, ss_duration, ss_content  from scenic_spot \n" +
                "where ss_id = ? ";
        super.executeQuery(sql,new Object[]{id});
        try{while(rs.next()){
            scenicSpot = new ScenicSpot();
            scenicSpot.setSsId(rs.getString("ss_id"));
            scenicSpot.setSsName(rs.getString("ss_name"));
            scenicSpot.setSsDuration(rs.getString("ss_duration"));
            scenicSpot.setSsContent(rs.getString("ss_content"));
            spotList.add(scenicSpot);
        }
        }catch (SQLException e) {
            e.printStackTrace();
        } finally {
            super.closeAll(rs,pstmt,conn);
        }
        return spotList;
    }

}
